package com.imti.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.imti.entity.Doctor;
import com.imti.entity.dto.DoctorDto;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * (Doctor)表数据库访问层
 *
 * @author makejava
 * @since 2023-01-30 15:52:20
 */
@Mapper
public interface DoctorDao extends BaseMapper<Doctor> {

    @Select("select * from doctor where 2=2")
    public List<Doctor> getDoc(Page page);

//    public List<Doctor> getDocBySQLLimit(@Param("pageNum") Integer pageNum, @Param("pageSize") Integer pageSize);

    @Select("<script>"+
            "SELECT doc.doc_id,doc.doc_name,doc.doc_job,des.desk_name,doc.doc_intro,doc.doc_img\n" +
            "FROM doctor doc,desk_work des\n" +
            "WHERE doc.desk_id=des.desk_id \n" +
            "<if test='searchDocName!=null and searchDocName!=\"\"'>"+
            "and doc.doc_name like concat('%',#{searchDocName},'%')"+
            "</if>"+
            "<if test='array!=null and searchDocName!=\"\"'>"+
            "and des.desk_id in"+
            "<foreach collection='array' item='deskId' open='(' close=')' separator=','>"+
            "#{deskId}"+
            "</foreach>"+
            "</if>"+
            "</script>"
    )
    public List<DoctorDto> findDoctorByDeskIdAndName(String searchDocName,Integer[] array);

    @Select("SELECT doc.doc_name,doc.doc_job,dw.desk_name,doc.doc_intro,doc.doc_img FROM doctor doc,desk_work dw WHERE doc.`desk_id`=dw.`desk_id` AND doc.`doc_id`=#{doc_id}")
    public List<DoctorDto> findDoctorById(Integer docId);


}

